import os
import zipfile


def zip_dir(dir_path, zip_path):
    """
    :param dir_path:目标文件夹路径
    :param zip_path:压缩后文件夹路径
    """
    zip = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
    for root, dirnames, filenames in os.walk(dir_path):
        file_path = root.replace(dir_path, '')
        for filename in filenames:
            zip.write(os.path.join(root, filename), os.path.join(file_path, filename))
    zip.close()


if __name__ == '__main__':
    current_path = os.path.dirname(__file__)
    dir_path = os.path.join(current_path, '../../..', 'reports/自动化测试报告V1.6')
    zip_dir(dir_path, dir_path + '/../email自动化报告.zip')
